<?php

$dirBase = 'temp_gen';

// the name of your zip archive to be created
$zipfile = $dirBase."/".$name.'.zip';

// DO NOT TOUCH BELOW IF YOU DONT KNOW WHAT IT IS
// all the process below

$filenames = array();

// function that browse the directory and all subdirectories inside

function browse($dir) {

global $filenames;

    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && is_file($dir.'/'.$file)) {
                $filenames[] = $dir.'/'.$file;
            }
            else if ($file != "." && $file != ".." && is_dir($dir.'/'.$file)) {
                browse($dir.'/'.$file);
            }
        }
        closedir($handle);
    }    
    return $filenames;
}

$filenames = browse($directory);

// creating zip archive, adding browsed files

$zip = new ZipArchive();

if ($zip->open($zipfile, ZIPARCHIVE::CREATE)!==TRUE) {
    die("cannot open <$zipfile>\n");
}

foreach ($filenames as $filename) {
#    echo "Adding " . $filename . "<br/>";
    $zip->addFile($filename,$filename);
}

#echo "numfiles: " . $zip->numFiles . "\n";
#echo "status:" . $zip->status . "\n";
$zip->close();

echo '<p class="align-center" style="padding: 0"><a href="'.$zipfile.'" class="big-button" style="padding: 30px; font-size: x-large;">Baixe o Seu Projeto Aki!!!</a></p>';

?>